//
//  YMHealthFileRecordListCell.m
//  YMMedical
//
//  Created by y s on 2023/7/21.
//

#import "YMHealthFileRecordListCell.h"


@interface YMHealthFileRecordListCell ()

@property (nonatomic, strong) UIView *vBg;
@property (nonatomic, strong) UILabel *lblName;
@property (nonatomic, strong) UILabel *lblTime;
@property (nonatomic, strong) UILabel *lblResult;
@property (nonatomic, strong) UIButton *btnDetail;

@end

@implementation YMHealthFileRecordListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI methods
- (void)setUI{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    
    [self.contentView addSubview:self.vBg];
    [self.vBg addSubview:self.lblName];
    [self.vBg addSubview:self.lblTime];
    [self.vBg addSubview:self.lblResult];
    [self.vBg addSubview:self.btnDetail];
    
    [self.vBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.top.mas_equalTo(0);
    }];
    [self.lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.top.mas_equalTo([SFitUtil fit:16]);
        make.right.lessThanOrEqualTo(self.lblResult.mas_left).offset([SFitUtil fit:-5]);
    }];
    [self.lblTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.bottom.mas_equalTo([SFitUtil fit:-15]);
    }];
    [self.lblResult mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo([SFitUtil fit:16]);
        make.right.mas_lessThanOrEqualTo([SFitUtil fit:-15]);
    }];
    [self.lblName setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
    [self.lblResult setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];

    [self.btnDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.bottom.mas_equalTo([SFitUtil fit:-15]);
        make.size.mas_equalTo([SFitUtil fitSize:64 height:27]);
    }];
}


#pragma mark - public methods
+ (CGFloat)getCellHeight{
    return [SFitUtil fit:88];
}
- (void)setDict:(NSDictionary *)dict{
    _dict = dict;
    
    self.lblResult.text = [NSString stringWithFormat:@"%@:%@",KLanguage(@"result_txt"),[SDataUtil stringOf:dict[@"primaryResDisplay"]]];
    self.lblTime.text = [NSString stringWithFormat:@"%@%@",[SDataUtil stringOf:dict[@"collectTime"]],KLanguage(@"generate_txt")];
    self.lblName.text = [SDataUtil stringOf:dict[@"minorTermName"]];
    
}

#pragma mark - Event Action
- (void)detailClickAction:(id)sender{
    
}


#pragma mark - setter and getter
- (UIView *)vBg{
    if (_vBg == nil){
        _vBg = [[UIView alloc] init];
        _vBg.backgroundColor = STheme.D9;
        _vBg.layer.cornerRadius = [SFitUtil fit:8];
        _vBg.clipsToBounds = YES;
    }
    return _vBg;
}
- (UILabel *)lblName{
    if (_lblName == nil){
        _lblName = [[UILabel alloc] init];
        _lblName.textColor = [SUIUtil colorOf:0x330000];
        _lblName.font = [SFitUtil fitBoldFont:14];
    }
    return _lblName;
}
- (UILabel *)lblTime{
    if (_lblTime == nil){
        _lblTime = [[UILabel alloc] init];
        _lblTime.textColor = STheme.D1;
        _lblTime.font = [SFitUtil fitFont:12];
    }
    return _lblTime;
}
- (UILabel *)lblResult{
    if (_lblResult == nil){
        _lblResult = [[UILabel alloc] init];
        _lblResult.textColor = [SUIUtil colorOf:0x330000];
        _lblResult.font = [SFitUtil fitBoldFont:14];
        _lblResult.numberOfLines = 0;
    }
    return _lblResult;
}
- (UIButton *)btnDetail{
    if (_btnDetail == nil){
        _btnDetail = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btnDetail addTarget:self action:@selector(detailClickAction:) forControlEvents:UIControlEventTouchUpInside];
        _btnDetail.backgroundColor = STheme.D9;
        _btnDetail.layer.cornerRadius = [SFitUtil fit:4];
        _btnDetail.clipsToBounds = YES;
        _btnDetail.layer.borderWidth = [SFitUtil fitLine];
        _btnDetail.layer.borderColor = [SUIUtil colorOf:0xCCCCCC].CGColor;
        [_btnDetail setTitle:KLanguage(@"detail_txt") forState:UIControlStateNormal];
        _btnDetail.titleLabel.font = [SFitUtil fitFont:14];
        [_btnDetail setTitleColor:STheme.D12 forState:UIControlStateNormal];
        _btnDetail.enabled = NO;
    }
    return _btnDetail;
}
@end
